package com.vn.ld.btc.fe.web.action;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.vn.ld.api.order.context.OrderContext;
import com.vn.ld.btc.fe.business.IOrderManager;
import com.vn.ld.btc.fe.model.OrderModel;
import com.vn.ld.common.Constants;

public class OrderWebAction extends ActionSupport implements ModelDriven<OrderModel>, ServletRequestAware,ServletResponseAware  {
	
	private static final long serialVersionUID = 1L;
	private OrderModel model = new OrderModel();
	private IOrderManager orderManager;
	private HttpServletRequest request = null; 
	private HttpServletResponse response = null;
	
	
	public String initOrderScreen(){
		return SUCCESS;
	}
	
	/**
	 * Customer sell btc
	 * @return
	 */
	public String customerSellBtc() {
		try {
			String action = request.getParameter(Constants.OrderInfo.ACTION);
			String ammount = request.getParameter(Constants.OrderInfo.AMMOUNT);
			String pricePer = request.getParameter(Constants.OrderInfo.PRICE_PER);
			
			if(!action.isEmpty() && !ammount.isEmpty() && !pricePer.isEmpty()) {
				PrintWriter printWriter = response.getWriter();
				//printWriter.print();
				printWriter.flush();
				printWriter.close();
			} else {
				
			}
			OrderContext context = model.getOrderContext();
			if(context != null) {
			
			} else {
				
			}
		} catch (Exception e) {
			System.out.print(e.getStackTrace());
		}
		return SUCCESS;
	}
	

	/**
	 * When customer click action change symbol to get more data
	 * @return
	 */
	public String customerChangeSymbolData() {
		return SUCCESS;
	}
	
	//////////////////////////////////
	@Override
	public OrderModel getModel() {
		return model;
	}

	public IOrderManager getOrderManager() {
		return orderManager;
	}

	public void setOrderManager(IOrderManager orderManager) {
		this.orderManager = orderManager;
	}

	public void setModel(OrderModel model) {
		this.model = model;
	}
	
	@Override
	public void setServletRequest(HttpServletRequest request) {
		this.request = request;		
	}

	@Override
	public void setServletResponse(HttpServletResponse response) {
		this.response = response;
		
	}
}
